package com.tanhua.dubbo.api.impl;

import com.baomidou.mybatisplus.core.conditions.Wrapper;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.tanhua.domain.db.UserStateInfo;
import com.tanhua.dubbo.api.UserStateInfoApi;
import com.tanhua.dubbo.mapper.UserStateInfoMapper;
import org.apache.dubbo.config.annotation.Service;
import org.springframework.beans.factory.annotation.Autowired;

@Service
public class UserStateInfoApiImpl implements UserStateInfoApi {

    @Autowired
    private UserStateInfoMapper userStateInfoMapper;

    /**
     * //根据id查询用户的冻结状态
     *
     * @param userId
     * @return
     */
    @Override
    public UserStateInfo findUserStateById(Long userId) {

        return userStateInfoMapper.selectById(userId);


    }

    /**
     * 根据id删除用户的冻结状态
     *
     * @param userId
     */
    @Override
    public void deleteStateById(Long userId) {
        QueryWrapper<UserStateInfo> wrapper = new QueryWrapper<>();
        wrapper.eq("id", userId);
        userStateInfoMapper.delete(wrapper);
    }

    @Override
    public void saveFreezeUser(Integer userId, Integer freezingTime,
                               Integer freezingRange, String reasonsForFreezing, String frozenRemarks) {
        UserStateInfo userStateInfo = new UserStateInfo();
        userStateInfo.setId(userId.longValue());
        userStateInfo.setUserStatus(freezingRange);
        userStateInfo.setExpire(freezingTime);
        userStateInfo.setCause(reasonsForFreezing);
        userStateInfo.setRemark(frozenRemarks);

        userStateInfo.setCreated(System.currentTimeMillis());

        userStateInfoMapper.insert(userStateInfo);
    }
}
